//
// Created by tunm on 2024/3/14.
//

#ifndef SIMPLESEMANTIC_PREDICTOR_H
#define SIMPLESEMANTIC_PREDICTOR_H

#include "semantic_classify/semantic_cls.h"
#include <future>
#include <thread>
#include <mutex>

#define PROCESS Predictor::GetInstance()

namespace solex {

class Predictor {
public:

    Predictor(const Predictor&) = delete;

    Predictor& operator=(const Predictor&) = delete;

    RetCode Initialization(const Configuration& param);

    RetCode AnalyseSentence(const Sentence & sentence, AnalysisResult& output);

    static std::shared_ptr<Predictor> GetInstance() {
        static std::shared_ptr<Predictor> instance(new Predictor());
        return instance;
    }

private:

    Predictor();

    void _waiting();

private:

    std::shared_ptr<SemanticCls> m_semantic_cls_;

    float m_threshold_{0.8f};

    std::future<int32_t> m_init_future_; //Used for asynchronous initialization
    std::atomic<bool> m_initialized_{false}; // Check that initialization is complete
    std::atomic<int32_t> m_init_error_code_{0}; // Initialization error code

    std::mutex m_mutex;
};

}   // namespace solex

#endif //SIMPLESEMANTIC_PREDICTOR_H
